/*************************************************************************
	> File Name: 004.使用共用体实现ip转整数的功能.c
	> Author: Maureen 
	> Mail: Maureen@qq.com 
	> Created Time: 五  8/27 11:57:20 2021
 ************************************************************************/

#include <stdio.h>

union IP {
    struct {
        unsigned char a1;
        unsigned char a2;
        unsigned char a3;
        unsigned char a4;
    } ip;
    unsigned int num;
};

int main() {
    union IP p;
    char str[100];
    int arr[4];
    while (~scanf("%s", str)) {
        sscanf(str, "%d.%d.%d.%d", arr + 0, arr + 1, arr + 2, arr + 3);
        //因为系统是小端机，对于192.168.0.1，即共用体的第0号字节存储的是1, 1号字节存储的是0，2号字节存储的是168，3号字节存储的是192
        //为了保证得到的结果的正确性，所以需要在对应的字节中倒着存储输入的数据
        p.ip.a1 = arr[3];
        p.ip.a2 = arr[2];
        p.ip.a3 = arr[1];
        p.ip.a4 = arr[0];
        printf("%s corresponding num is %u\n", str, p.num);
    }
    return 0;
}
//运行测试结果：
//192.168.0.1
//192.168.0.1 corresponding num is 3232235521
//192.168.0.2
//192.168.0.2 corresponding num is 3232235522
